package com.arturjaneczko.view.impl;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.arturjaneczko.model.core.IModel;
import com.arturjaneczko.view.core.AView;

public class View extends AView {

	private JFrame frame;

	public View(IModel model) {
		super(model);
		compositeList = new ArrayList<>();
	}

	@SuppressWarnings("unused")
	private Dimension getScreenSize() {
		return Toolkit.getDefaultToolkit().getScreenSize();
	}

	@Override
	public void ui() {
		frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		String laf = UIManager.getSystemLookAndFeelClassName();
		try {
			UIManager.setLookAndFeel(laf);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}

		// frame constraint: null
		uiComposite(this, frame.getContentPane(), null);
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
//				Window w = e.getWindow();
//				w.setVisible(false);
//				w.dispose();
//				System.exit(0);
				System.out.println("ZAMYKAM");
			}
		});

		frame.pack();
		frame.setVisible(true);
	}

}
